package com.sanpu.kxe.business.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.jump.shareutil.share.SharePlatform;

import java.util.ArrayList;

/**
 * Description：分享Adapter
 * Created by 薛勇军 on 2018/6/12.
 */

public class ShareAdapter extends BaseAdapter{

    private LayoutInflater layoutInflater;
    private ArrayList<ShareModuleItem> mPlatformsList = new ArrayList<>();

    public ShareAdapter(Context context) {
        this(context, false);
    }

    public ShareAdapter(Context context, boolean hasQQ) {
        layoutInflater = LayoutInflater.from(context);
        mPlatformsList.add(new ShareModuleItem(R.drawable.ic_share_wechat, SharePlatform.WX, "微信"));
        mPlatformsList.add(new ShareModuleItem(R.drawable.ic_share_timeline, SharePlatform.WX_TIMELINE, "朋友圈"));
        if (hasQQ) {
            mPlatformsList.add(new ShareModuleItem(R.drawable.ic_share_qq, SharePlatform.QQ, "QQ"));
            mPlatformsList.add(new ShareModuleItem(R.drawable.ic_share_qzone, SharePlatform.QZONE, "QQ空间"));
        }
    }

    @Override
    public int getCount() {
        return mPlatformsList.size();
    }

    @Override
    public ShareModuleItem getItem(int position) {
        return mPlatformsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public ArrayList<ShareModuleItem> getData() {
        return mPlatformsList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;

        if (view == null) {
            view = layoutInflater.inflate(R.layout.item_share, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.textView = view.findViewById(R.id.text_view);
            viewHolder.imageView = view.findViewById(R.id.image_view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.imageView.setBackgroundResource(getItem(position).getIcon());
        viewHolder.textView.setText(getItem(position).getTitle());

        return view;
    }

    class ViewHolder {
        TextView textView;
        ImageView imageView;
    }

    public class ShareModuleItem {
        private int icon;
        private String title;
        private int platform;

        public ShareModuleItem(int icon, @SharePlatform.Platform int platform, String title) {
            this.icon = icon;
            this.title = title;
            this.platform = platform;
        }

        public int getIcon() {
            return icon;
        }

        public void setIcon(int icon) {
            this.icon = icon;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public
        @SharePlatform.Platform
        int getPlatform() {
            return platform;
        }

        public void setPlatform(int platform) {
            this.platform = platform;
        }
    }
}
